using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class GuarantorContractMap : EntityTypeConfiguration<GuarantorContract>
    {
        public GuarantorContractMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.GuarantorId)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.ContractNumber)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("GuarantorContract");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.StartDate).HasColumnName("StartDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.GuarantorId).HasColumnName("GuarantorId");
            this.Property(t => t.CeilCurrency).HasColumnName("CeilCurrency");
            this.Property(t => t.ContractDate).HasColumnName("ContractDate");
            this.Property(t => t.ContractNumber).HasColumnName("ContractNumber");
            this.Property(t => t.Note).HasColumnName("Note");

            // Relationships
            this.HasRequired(t => t.Cust)
                .WithMany(t => t.GuarantorContracts)
                .HasForeignKey(d => d.GuarantorId);

        }
    }
}
